package contest.sweek204;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/8/30 10:28
 */
public class Solution2 {
    public int getMaxLen(int[] nums) {
        int n = nums.length;
        int res = 0;
        int pre = 0;
        for (int i = 0; i < n; ) {
            if (nums[i] == 0) {
                i++;
                continue;
            }
            int j = i;
            for (; j < n; j++) {
                if (nums[j] == 0) {
                    i = j + 1;
                    break;
                }
                if (i == j) pre = nums[j] > 0 ? 1 : -1;
                else if (nums[j] > 0) {
                    pre = pre > 0 ? 1 : -1;
                } else if (nums[j] < 0) {
                    pre = pre > 0 ? -1 : 1;
                }
                if (pre == 1) res = Math.max(res, j - i + 1);
            }
            if (j == n) break;
        }
        return res;
    }
}
